package com.first.nell.me

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.first.nell.ProjectApplication
import com.first.nell.R
import com.first.nell.base.BaseViewModel
import com.first.nell.components.dialog.PopListItem
import com.first.nell.data.ReqBase
import com.first.nell.data.ReqSaveFeedback
import com.first.nell.data.DataCustomizeContact
import com.first.nell.network.ApiUserReposity
import com.first.nell.utils.AppConfigUtil

class MeViewModel : BaseViewModel() {

    var mFirstNellCustomerFirstNellServiceFirstNellList = mutableListOf<DataCustomizeContact>()
    var mFirstNellFeedbackFirstNellTypeFirstNellList = mutableListOf<PopListItem>()

    val onFirstNellFetchFirstNellContactFirstNellListFirstNellFromFirstNellCachedFirstNellLiveData =
        MutableLiveData<List<DataCustomizeContact>>()
    private val mFirstNellFetchFirstNellContactFirstNellListFirstNellLiveData =
        MutableLiveData<ReqBase>()
    private val mFirstNellSaveFirstNellFeedbackFirstNellLiveData = MutableLiveData<ReqSaveFeedback>()

    val onFirstNellFetchFirstNellContactFirstNellListFirstNellLiveData =
        Transformations.switchMap(mFirstNellFetchFirstNellContactFirstNellListFirstNellLiveData) { query ->
            ApiUserReposity.fetchFirstNellContactFirstNellList(this, query)
        }

    val onFirstNellSaveFirstNellFeedbackFirstNellLiveData =
        Transformations.switchMap(mFirstNellSaveFirstNellFeedbackFirstNellLiveData) { query ->
            ApiUserReposity.saveFirstNellFeedback(this, query)
        }

    fun fetchFirstNellContactFirstNellList(reqBase: ReqBase) {
        mFirstNellCustomerFirstNellServiceFirstNellList.clear()
        val contacts = AppConfigUtil.getCashArrwoCustomerFirstNellServiceFirstNellCnotacts()
        mFirstNellCustomerFirstNellServiceFirstNellList.addAll(contacts)

        if (mFirstNellCustomerFirstNellServiceFirstNellList.isEmpty()) {
            mFirstNellFetchFirstNellContactFirstNellListFirstNellLiveData.value = reqBase
        } else {
            onFirstNellFetchFirstNellContactFirstNellListFirstNellFromFirstNellCachedFirstNellLiveData.value =
                mFirstNellCustomerFirstNellServiceFirstNellList
        }
    }

    fun saveFirstNellFeedback(reqSaveFeedback: ReqSaveFeedback) {
        mFirstNellSaveFirstNellFeedbackFirstNellLiveData.value = reqSaveFeedback
    }

    fun initFirstNellFeedbackFirstNellType() {
        //SUGGEST,BUG,PAYMENT,OTHER
        mFirstNellFeedbackFirstNellTypeFirstNellList.clear()
        mFirstNellFeedbackFirstNellTypeFirstNellList.add(
            PopListItem(
                display = ProjectApplication.context.getString(
                    R.string.first_nell_product_suggestion
                ), content = "SUGGEST"
            )
        )
        mFirstNellFeedbackFirstNellTypeFirstNellList.add(
            PopListItem(
                display = ProjectApplication.context.getString(
                    R.string.first_nell_app_bugs
                ),
                content = "BUG"
            )
        )
        mFirstNellFeedbackFirstNellTypeFirstNellList.add(
            PopListItem(
                display = ProjectApplication.context.getString(
                    R.string.first_nell_payment_issues
                ),
                content = "PAYMENT"
            )
        )
        mFirstNellFeedbackFirstNellTypeFirstNellList.add(
            PopListItem(
                display = ProjectApplication.context.getString(
                    R.string.first_nell_others
                ),
                content = "OTHER"
            )
        )
    }

}